<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: zzz
  Date: 2020/2/9
  Time: 10:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="utf-8" />
    <title>最家</title>
    <link rel="stylesheet" type="text/css" href="${APP_PATH}/portal/css/public.css"/>
    <link rel="stylesheet" type="text/css" href="${APP_PATH}/portal/css/mygxin.css" />
</head>
<body>
<!------------------------------head------------------------------>
<jsp:include page="/WEB-INF/jsps/Portal/common/top.jsp"/>
<!------------------------------idea------------------------------>
<div class="address">
    <div class="wrapper clearfix">
        <a href="${APP_PATH}/toPortal" class="fl">首页</a>
        <span>/</span>
        <a href="${APP_PATH}/toUser">个人中心</a>
        <span>/</span>
        <a href="${APP_PATH}/toAddress" class="on">地址管理</a>
    </div>
</div>

<!------------------------------Bott------------------------------>
<span hidden id="path">${APP_PATH}/</span>
<div class="Bott">
    <div class="wrapper clearfix">
        <jsp:include page="/WEB-INF/jsps/Portal/common/nav.jsp"/>
        <div class="you fl">
            <h2>收货地址</h2>
            <div style="width: 900px;" class="add">
                <div>
                    <a style="position: relative; left:-15px;" href="javascript:;" id="addxad"><img src="${APP_PATH}/portal/img/jia.png"/></a>
                    <span style="position: relative; left:-15px;">添加新地址</span>
                </div>
                <c:forEach items="${requestScope.addressInfoList}" var="addressInfo">
                    <div class="dizhi">
                        <span hidden class="adid">${addressInfo.address.adid}</span>
                        <p>${addressInfo.address.consignee}</p>
                        <p>${addressInfo.address.cphone}</p>
                        <p>${addressInfo.province.pname} ${addressInfo.district.dname} ${addressInfo.area.arname}</p>
                        <p>${addressInfo.address.address}（${addressInfo.address.postcode}）</p>
                    </div>
                </c:forEach>
            </div>


            </div>
        </div>
    </div>

<!--编辑弹框-->
<!--遮罩-->
<div class="mask"></div>
<div class="adddz">
    <form action="${APP_PATH}/user/insertAddress" method="post">
        <input type="text" name="consignee" placeholder="姓名" class="on" />
        <input type="text" name="cphone" placeholder="手机号" />
        <div class="city">
            <select id="province">
                <option value="省份/自治区">省份/自治区</option>
            </select>
            <select id="city">
                <option value="城市/地区">城市/地区</option>
            </select>
            <select id="district">
                <option value="区/县">区/县</option>
            </select>
            <select id="area" name="ar_arid">
                <option value="配送区域">配送区域</option>
            </select>
        </div>
        <textarea name="address" rows="" cols="" placeholder="详细地址"></textarea>
        <input name="postcode" type="text" placeholder="邮政编码" />
        <div class="bc">
            <input type="submit" value="保存" />
            <input type="button" value="取消" />
        </div>
    </form>
</div>
<div class="readd">
    <form action="${APP_PATH}/user/updateAddress" method="post">
        <input type="hidden" id="adid" name="adid">
        <input type="text" id="consignee" name="consignee"  class="on" value="" />
        <input type="text" id="cphone" name="cphone" value="" />
        <div class="city">
            <select id="province2">
                <option value="省份/自治区"></option>
            </select>
            <select id="city2">
                <option value="城市/地区"></option>
            </select>
            <select id="district2">
                <option value="区/县"></option>
            </select>
            <select id="area2" name="ar_arid">
                <option value="配送区域"></option>
            </select>
        </div>
        <textarea id="address" name="address" rows="" cols="" placeholder="详细地址"></textarea>
        <input type="text" id="postcode" name="postcode" placeholder="邮政编码" value=""/>
        <div class="bc">
            <input type="submit" value="保存" />
            <input type="button" value="取消" />
        </div>
    </form>
</div>
<!--返回顶部-->

<jsp:include page="/WEB-INF/jsps/Portal/common/gotop.jsp"/>

<!--footer-->
<jsp:include page="/WEB-INF/jsps/Portal/common/bottom.jsp"/>
<script src="${APP_PATH}/portal/js/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="${APP_PATH}/portal/js/public.js" type="text/javascript" charset="utf-8"></script>
<script src="${APP_PATH}/portal/js/user.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
<script>
    $(function () {
        if(${requestScope.msg != null}){
            alert('${requestScope.msg}');
        }
        $.ajax({
            url : "${APP_PATH}/user/getAllProvince",
            method : "GET",
            success : function (result) {
                if(result.success){
                    var provinceList = result.data;
                    var provinceContent = "";
                    provinceContent +='<option value="0">省份/自治区</option>';
                    for(var i = 0; i < provinceList.length; i++){
                        provinceContent +='<option value="'+provinceList[i].pid+'">'+provinceList[i].pname+'</option>';
                    }
                    $("#province").html(provinceContent);
                    $("#province2").html(provinceContent);
                }
            }
        });

        $("#province").change(function () {
            getCity($(this).val(),1);
            $("#district").html('<option value="0">区/县</option>');
            $("#area").html('<option value="0">配送区域</option>');
        });
        $("#city").change(function () {
            getDistrict($(this).val(),1);
            $("#area").html('<option value="0">配送区域</option>');
        });
        $("#district").change(function () {
            getArea($(this).val(),1);
        });
    });

    function getCity(pid,num,cid) {
            $.ajax({
                url : "${APP_PATH}/user/getCityByPid",
                method : "GET",
                data : {
                    pid : pid
                },
                success : function (result) {
                    if(result.success){
                        var cityList = result.data;
                        var cityContent = "";
                        cityContent +='<option value="0">城市/地区</option>';
                        for(var i = 0; i < cityList.length; i++){
                            cityContent +='<option value="'+ cityList[i].cid+'">'+ cityList[i].cname+'</option>';
                        }
                        if(num == 1){
                            $("#city").html(cityContent);
                        }else{
                            $("#city2").html(cityContent);
                            $("#city2").val(cid);
                        }
                    }
                }
            });
    }

    function getDistrict(cid,num,did) {
            $.ajax({
                url : "${APP_PATH}/user/getDistrictByCid",
                method : "GET",
                data : {
                    cid : cid
                },
                success : function (result) {
                    if(result.success){
                        var districtList = result.data;
                        var districtContent = "";
                        districtContent +='<option value="0">区/县</option>';
                        for(var i = 0; i < districtList.length; i++){
                            districtContent +='<option value="'+ districtList[i].did+'">'+ districtList[i].dname+'</option>';
                        }
                        if(num == 1){
                            $("#district").html( districtContent);
                        }else{
                            $("#district2").html( districtContent);
                            $("#district2").val(did);
                        }
                    }
                }
            });
    }

    function getArea(did,num,arid) {
            $.ajax({
                url : "${APP_PATH}/user/getAreaByDid",
                method : "GET",
                data : {
                    did : did
                },
                success : function (result) {
                    if(result.success){
                        var areaList = result.data;
                        var areaContent = "";
                        areaContent +='<option value="0">配送区域</option>';
                        for(var i = 0; i < areaList.length; i++){
                            areaContent +='<option value="'+ areaList[i].arid+'">'+ areaList[i].arname+'</option>';
                        }
                        if(num == 1){
                            $("#area").html( areaContent);
                        }else{
                            $("#area2").html( areaContent);
                            $("#area2").val(arid);
                        }
                    }
                }
        });
    }
</script>
